// pages/pay/pay.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    receiveRoute:{},
    statusBarHeight: app.globalData.statusBarHeight,
    menuHeight:app.globalData.navBarHeight  
  },
  aa(){
   
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
  //    {
  //    // 组购支付接口 /payment/getActivityOrder
        // 参数除了subjectId改成subjectIds其他都一样
        // subjectIds超过一个的用逗号隔开如:21,19,17
  // }

  // 支付接口
  payorder:function(e){
    let token = wx.getStorageSync("token")?JSON.parse(wx.getStorageSync("token")):''
    // console.log(token)
     let that  = this;
     wx.request({
       url: 'https://api.jiudaifu.com/v2/payment/getActivityOrder', //测试接口
       data: {
         username: '20140010',
         subjectIds: '21,20,19',
         real_price:0.01,
         good_name:'捏捏小手百病消',
         openid:'otz_s0DO3KIeOh7ysHq-x9wfSeY4'
       },
       header: {
         'content-type': 'application/json', // 默认值
         'Authorization': 'Bearer '+token
       },
       success: function(res) { 
         console.log("checkActivationStatus   data = ",res.data);
         if(res.data.error == 0){
           var orderInfo = res.data.data;
           wx.requestPayment({
             nonceStr: orderInfo.nonceStr,
             package: orderInfo.package,
             paySign: orderInfo.sign,
             timeStamp: String(orderInfo.timeStamp),
             signType:orderInfo.signType,
             success:function(e){
               console.log('支付成功');
             },
             fail:function(e){
               console.log("支付失败 =",e);
             }
           })
         }
       },
       fail:function(res){  }
     });




  //   let token = JSON.parse(wx.getStorageSync("token"))
  //  // console.log(token)
  //   let that  = this;
  //   wx.request({
  //     url: 'https://api.jiudaifu.com/v2/payment/getXiaochengXuOrder', //测试接口
  //     data: {
  //       username: '20140010',
  //       subjectId: 21,
  //       real_price:0.01,
  //       good_name:'捏捏小手百病消',
  //       openid:'otz_s0DO3KIeOh7ysHq-x9wfSeY4'
  //     },
  //     header: {
  //       'content-type': 'application/json', // 默认值
  //       'Authorization': 'Bearer '+token
  //     },
  //     success: function(res) { 
  //       console.log("checkActivationStatus   data = ",res.data);
  //       if(res.data.error == 0){
  //         var orderInfo = res.data.data;
  //         wx.requestPayment({
  //           nonceStr: orderInfo.nonceStr,
  //           package: orderInfo.package,
  //           paySign: orderInfo.sign,
  //           timeStamp: String(orderInfo.timeStamp),
  //           signType:orderInfo.signType,
  //           success:function(e){
  //             console.log('支付成功');
  //           },
  //           fail:function(e){
  //             console.log("支付失败 =",e);
  //           }
  //         })
  //       }
  //     },
  //     fail:function(res){  }
  //   });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   // let receiveRoute = JSON.parse(options.info)
   // console.log(receiveRoute,777)
    // this.setData({
    //   receiveRoute: receiveRoute
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})